home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / vgamaze4.zip / HEXAGON.CPP < prev    next >
C/C++ Source or Header  |  1994-03-02  |  4KB  |  137 lines

  1. //
  2. //       This program will generate a three dimensional maze on a VGA display.
  3. //  A different random number seed will produce a different maze.
  4. //
  5. //       Written by James L. Dean
  6. //                  406 40th Street
  7. //                  New Orleans, LA 70124-1532
  8. //
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <math.h>
  12. #include <stdlib.h>
  13. #include <conio.h>
  14. #include <time.h>
  15. #include <iostream.h>
  16. #include "oracle.h"
  17. #include "cell.h"
  18. #include "titillat.h"
  19. #include "hexmaze.h"
  20. #include "plot3d.h"
  21. #include "vga3d.h"
  22.  
  23. #ifndef TRUE
  24. #define TRUE -1
  25. #endif
  26. #ifndef FALSE
  27. #define FALSE 0
  28. #endif
  29.  
  30. // maze constants
  31. #define PIXELS_PER_ROOM 40
  32. #define RESOLUTION       4  // larger values takes more time (and virtual
  33.                             // memory) but produce a better image
  34.  
  35. static int    external_to_plot(double,double);
  36. static double f(double,double);
  37.        int    main(void);
  38. static int    red(double,double);
  39.  
  40. extern unsigned _stklen=0x8000;
  41.        maze     *maze_ptr;
  42.  
  43. int main()
  44.     {
  45.       static   int    fatal_error;
  46.       static   int    num_columns;
  47.       static   int    num_rows;
  48.       static   double light_x;
  49.       static   double light_y;
  50.       static   double light_z;
  51.       static   int    response;
  52.       static   double rotation;
  53.       static   char   seed [9];
  54.                time_t start_time;
  55.                time_t stop_time;
  56.       static   double tilt;
  57.       static   vga3d  *vga3d_ptr;
  58.  
  59.       fatal_error=FALSE;
  60.       clrscr();
  61.       cout << "                                 Maze Generator"
  62.        << '\n' << '\n' << '\n' << '\n';
  63.       cout << "     After the maze is displayed, press \"S\" to see the "
  64.        << "solution or another" << '\n';
  65.       cout << "key to exit.  If the solution is displayed, press any key "
  66.        << "to exit." << '\n';
  67.       cout << "\n     Random number seed? ";
  68.       cin.get(&seed[0],9,'\n');
  69.       time(&start_time);
  70.       stop_time=start_time;
  71.       vga3d_ptr=new vga3d();
  72.       num_columns=(2*(vga3d_ptr->num_x_pixels()))/(3*PIXELS_PER_ROOM)-1;
  73.       num_columns=2*num_columns+1;
  74.       num_rows=(int) (((2.0/sqrt(3.0))
  75.        *(vga3d_ptr->aspect_ratio())
  76.        *((double) (vga3d_ptr->num_y_pixels())))
  77.        /((double) PIXELS_PER_ROOM));
  78.       maze_ptr=new maze(num_rows,num_columns,RESOLUTION,&seed[0]);
  79.       if (maze_ptr->constructed())
  80.         {
  81.           rotation=(double) 0.0;
  82.           tilt=(double) 30.0;
  83.           light_x=(double) 1.5;
  84.           light_y=(double) -1.0;
  85.           light_z=(double) 2.6;
  86.           if (vga3d_ptr->prepare_plot(f,maze_ptr->x_min(),maze_ptr->x_max(),
  87.            maze_ptr->y_min(),maze_ptr->y_max(),external_to_plot,red,
  88.            maze_ptr->num_x_divisions(),maze_ptr->num_y_divisions(),
  89.            rotation,tilt,light_x,light_y,light_z))
  90.             {
  91.               if (vga3d_ptr->plot("",FALSE,FALSE,1.0))
  92.                 {
  93.                   time(&stop_time);
  94.                   fflush(stdin);
  95.                   response=getch();
  96.                   fflush(stdin);
  97.                   if ((response == (int) 's')
  98.                   ||  (response == (int) 'S'))
  99.                     {
  100.                       if (vga3d_ptr->plot("",TRUE,FALSE,1.0))
  101.                         {
  102.                           fflush(stdin);
  103.                           response=getch();
  104.                           fflush(stdin);
  105.                         }
  106.                     }
  107.                 }
  108.             }
  109.         }
  110.       delete maze_ptr;
  111.       delete vga3d_ptr;
  112.       cout << "     It took " << stop_time-start_time  
  113.        << " seconds to generate and display the maze." << '\n';
  114.       return(fatal_error);
  115.     }
  116.  
  117. static int external_to_plot(
  118.   double x,
  119.   double y)
  120.     {
  121.        return maze_ptr->external_to_maze(x,y);
  122.     }
  123.  
  124. static int red(
  125.   double x,
  126.   double y)
  127.     {
  128.        return maze_ptr->part_of_solution(x,y);
  129.     }
  130.  
  131. static double f(
  132.   double x,
  133.   double y)
  134.     {
  135.        return maze_ptr->f(x,y);
  136.     }
  137.